Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make trivially_copy_pass_by_ref conditional on a 64-bit target. #77

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

xStrom
Copy link
Member

@xStrom xStrom commented Nov 27, 2024

Consider the following code:

#[derive(Copy, Clone)]
struct Foo {
    a: usize,
    b: usize,
    c: usize,
}

fn take_foo(foo: &Foo) {}

When targeting 64-bit Foo is 24 bytes and so doesn't trigger trivially_copy_pass_by_ref for take_foo.

However when targeting 32-bit Foo is 12 bytes, which is below our threshold of 16 bytes, and triggers the lint. Satisfying the lint doesn't make sense in the larger picture though, because Foo is still 24 bytes in the 64-bit world.

I ran into this issue in practice when adding our lint set to SimpleCSS.

Unfortunately our custom trivial-copy-size-limit can't be a multiplier of target_pointer_width even though the default value does that. So the solution is to make the lint apply only when targeting 64-bit. Can't do that in Cargo.toml so lib.rs it is. Luckily we don't care as much about this lint in the examples so it works out fine.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're making a v3, can we move clippy.fn_to_numeric_cast_any = "forbid" into the group of the other forbids? (alternatively, switching it to warn wouldn't be that unreasonable, as it's not really actively dangerous)

I was surprised it was forbid but hidden in the big block.

@xStrom
Copy link
Member Author

xStrom commented Nov 27, 2024

Yeah something like that makes sense, and I plan on suggesting some other changes too, but not today. All that to say, won't start widely deploying the new lint set immediately.

@xStrom xStrom merged commit f7b1de2 into linebender:main Nov 27, 2024
1 check passed
@xStrom xStrom deleted the bettercopy branch November 27, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants